package com.cow.framework.core.base;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import com.cow.framework.core.cache.RedisUtil;
import com.cow.framework.core.config.dict.DictUtil;
import com.cow.framework.core.config.parameter.ParameterUtil;
import com.cow.framework.utils.web.SessionUtil;
import com.cow.support.dto.User;
import com.cow.support.dto.UserSessionModel;
import com.cow.support.remote.AuthRemoteService;
import com.cow.support.remote.HessianClient;

/**
 *	控制类基类
 *
 *  @author yangsj
 */
public class BaseComponent{
	protected final Logger logger = LoggerFactory.getLogger(this.getClass());  
	@Autowired
	protected RedisUtil redisUtil;
	@Value("${spring.profiles.active}")
	protected String active;
	@Value("${app.fileHome}")
	protected String fileHome;
	@Value("${app.tempFileHome}")
	protected String tempFileHome;
	@Value("${spring.application.name}")
	protected String appName;
	@Autowired
	protected ParameterUtil parameterUtil;
	@Autowired
	protected DictUtil dictUtil;
	@Autowired
	protected HessianClient hessianClient;
	
	/**读取缓存*/
	protected Object getCache(String key){
		return redisUtil.get(key);
	}
	
	/**写入缓存*/
	protected void setCache(String key, Object value,Long expireTime){
		redisUtil.set(key,value,expireTime);
	}
	
	/**获取当前用户信息*/
	protected UserSessionModel getUserSession(){
		return  (UserSessionModel)SessionUtil.getSession().getAttribute("userSession");
	}
	
	/**获取当前用户信息*/
	protected User getCurUser(){
		return getUserSession().getUserInfo();
	}
	
	/**获取当前用户编号*/
	protected Integer getCurUserId(){
		return getCurUser().getUserid().intValue();
	}
	
	/**获取远程认证客户端*/
	protected AuthRemoteService getAuthClient(){
		return hessianClient.getClient();
	}
}
